-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
3-suhyun113 #12
3-suhyun113 #12
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
무ν 루νλ₯Ό ν΅ν΄ λ¬Έμ λ₯Ό ν μ μκ΅°μ!
μ λ μ²μμ for in range
λ₯Ό μ¬μ©ν΄μ μ
λ ₯λ°μ κ±°μ€λ¦λμ μ‘μκ° 0μ΄ λ λκΉμ§ λ°λ³΅ν΄μΌ νλ μΆμλλ° μν λμ²λΌ μ½λλ₯Ό μ§λ 쑰건λ μ λ€μ΄κ°κ³ μκ³ λ¦¬μ¦μ΄ ν¨μ¬ κ°νΈν κ² κ°μμ λλΆμ λ νλ μμκ°λλ· μκ³ νμ
¨μ΄μ!~
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
μ λ 그리λ λ°©μμΌλ‘ κ±°μ€λ¦λμ μ‘μλ₯Ό 5λ‘ λλμ΄λ¨μ΄μ§λκΉμ§ -2μ©νλ λ‘μ§μΌλ‘ νμλλ° DPλ‘λ ν μ μκ΅°μ..!
DPλ 곡λΆν΄μ λ€λ₯Έ λ°©λ²μΌλ‘λ νμ΄λ΄μΌκ² λ€μ :)
PR μκ³ νμ
¨μ΄μπ
κ±°μ€λ¦λ λ¬Έμ λνμ μΈ κ·Έλ¦¬λ μκ³ λ¦¬μ¦μ μ΄μ©ν λ¬Έμ λΌκ³ λ§ λ€μλλ° μ€μ λ‘ μνλμ΄ μμ±ν΄μ£Όμ μ½λλ₯Ό 보λ μλ‘κ² μκ² λλ μ λ€μ΄ λ§μ κ² κ°λ€μ!! λ€μ΄λλ―Ή νλ‘κ·Έλλ°μΌλ‘λ νκΈ° μ μ dp μ½λ μ°Έκ³ νμλ©΄ μ’μκ² κ°μμ! #define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#define min(A,B) A < B ? A : B
int main() {
int n, i, j;
scanf("%d", &n);
int* arr = (int*)calloc(n + 1, sizeof(int));
for (i = 0; i < n + 1; i++)
arr[i] = -1;
arr[2] = 1;
arr[5] = 1;
for (i = 3; i < n + 1; i++) {
if (arr[i - 2] != -1)
arr[i] = arr[i - 2] + 1;
if (arr[i - 5] != -1 && i > 5)
arr[i] = min(arr[i], arr[i - 5] + 1);
}
printf("%d", arr[n]);
return 0;
} |
π λ¬Έμ λ§ν¬
https://www.acmicpc.net/problem/14916
βοΈ μμλ μκ°
μ½ 1μκ°
β¨ μλ μ½λ
1. λ¬Έμ μ€λͺ
2. μ½λ μ€λͺ
κ±°μ€λ¦λ nμ μ λ ₯λ°μ μ΅μ’ μ μΌλ‘ μ΅μ λμ μ κ°μλ₯Ό ꡬνλ€.
2μκ³Ό 5μ μ€ 2μμ κ°μ΄ λ ν¬κΈ° λλ¬Έμ, λμ μ μ΅μ κ°μλ₯Ό ꡬν λ 5μλΆν° νλ³νλ€.
-> κ±°μ€λ¦λ n < 0 μ΄λ©΄ λ μ΄μ κ±°μ¬λ¬μ€ μ μμΌλ―λ‘ -1 μΆλ ₯νλ€.
3. μ΅μ’ μ½λ
π μλ‘κ² μκ²λ λ΄μ©
κ±°μ€λ¦λ λ¬Έμ λ μμ μκ°μ λ§μ΄ νμ΄λ³Έ κ² κ°μμ κ°λ¨ν κ²μ΄λΌκ³ μκ°νλκ² μ€μ°,,,μ΄μλ€.
2μκ³Ό 5μλ§ κ±°μ€λ¦λμΌλ‘ λ°μ μ μμ΄μΌ ν΄μ μ΄μ λν μκ³ λ¦¬μ¦μ μ§λ κ²μ΄ μ΄λ €μ λ€.
κ²°κ΅ μ¬λ¬ μ½λλ₯Ό μ°Ύμ보면μ μ΄ λ¬Έμ λ₯Ό μ΄ν΄νκ³ κ²¨μ° ν μ μμλ€.
μ°Έκ³ λ‘ μ΄ λ¬Έμ λ DPλ‘λ ν μ μλ κ² κ°μλλ°, λ€μλ²μ κΈ°νκ° λλ€λ©΄ DPκ°λ μ μ’ λ 곡λΆν΄μ
κ·Έ λ°©λ²μΌλ‘λ ν λ² νμ΄λ΄μΌκ² λ€.